from django.contrib import admin
from .models import SubmitInfo
from django.core.mail import send_mail


# Register your models here.
admin.site.site_header = '西安工程大学研讨间审批系统'
admin.site.site_title = '西安工程大学研讨间审批系统'

def make_pass(modeladmin, request, queryset):
    for info in queryset:
        email=str(str(info).splitlines()[0])
        send_mail('图书馆研讨间审批回复（自动发送请勿回复）', '您好，您的研讨室审批申请已经已通过审批\n'+str(info), 'xpu@mail.wangerniu.com',
                  [email], fail_silently=False)
    queryset.update(satu='通过未签到')
def make_unpass(modeladmin, request, queryset):
    for info in queryset:
        email=str(str(info).splitlines()[0])
        send_mail('图书馆研讨间审批回复（自动发送请勿回复）', '您好，抱歉，您的研讨室审批申请已经未通过审批\n'+str(info), 'xpu@mail.wangerniu.com',
                  [email], fail_silently=False)
    queryset.update(satu='未通过审核')
make_pass.short_description = "审批通过"  #这里的短描述是action下拉框中显
make_unpass.short_description = "审批不通过"  #这里的短描述是action下拉框中显
class InfoAdmin(admin.ModelAdmin):
    # list_display_links = None
    list_display = ('name', 'kahao','xueyuan','shenfen','phone','email','local' ,'people','time','date','use','satu',)
    list_filter = ('satu',)
    actions = [make_pass,make_unpass]


admin.site.register(SubmitInfo, InfoAdmin)
# admin.site.register(SubmitInfo)
